<template>
  <view style="background-color: #fff">
    <view class="title">机器人</view>
    <van-tabs
      v-model="active"
      swipeable
      animated
      sticky
    >
      <van-tab
        v-for="item in platform"
        :key="item.name"
        :title="item.name"
      >
        <scroll-view :scroll-top="scrollTop" scroll-y="true"
        >
          <view v-if="robot_list[item.label] && robot_list[item.label].length > 0">
            <view
              v-for="robot in robot_list[item.label]"
              :key="robot.id"
            >
              <van-cell
                class="asset-item"
                @click="goDetail(robot)"
              >
                <view class="center">
                  <view class="name">
                    {{ robot.market_name }}
                    <van-tag
                      v-if="robot && robot.recycle_status == 1"
                      round
                      type="primary"
                    >
                      循环策略
                    </van-tag>
                    <van-tag
                      v-if="robot && robot.recycle_status == 0"
                      round
                      type="primary"
                    >
                      单次策略
                    </van-tag>
                  </view>
                  <view
                    v-if="robot"
                    class="info"
                  >
                    <p>预计收益：{{ Number(robot.revenue) | numberFormat(5) }} {{ robot.money }}</p>
                    <p
                      v-if="robot.show_msg"
                      class="van-ellipsis"
                    >
                      持仓数量：{{ getDeal(robot.values_str) }} {{ robot.stock }}
                    </p>
                  </view>
                </view>
              </van-cell>
            </view>
          </view>
          <view
            v-else
            description="暂无运行中的机器人"
          />
        </scroll-view>
      </van-tab>
    </van-tabs>
  </view>
</template>

<script>
import { PLATFORM } from '@/constants/global'
export default {
  data () {
    return {
      active: 0,
      scrollTop: 0,
      isLoading: false,
      robot_list: {},
      platform:PLATFORM,
      robots:{}
    }
  },
  computed: {
    // ...mapState({
    //   platform: ({ robot }) => robot.platform,
    //   robots: ({ robot }) => robot.robotList
    // })
  },
  watch: {
    robots (values) {
      const list = values.filter(item => item.status === 1)
      this.platform.forEach((item) => {
        this.robot_list[item.label] = []
        for (const i in list) {
          if (list[i].platform === item.label) {
            this.robot_list[item.label].push(list[i])
          }
        }
      })
      forceUpdate()
    }
  },
  created () {
    this.loadData()
  },
  methods: {
    // ...mapActions({
    //   robotList: 'robot/robotList'
    // }),
    loadData () {
      var that=this
      // this.socketUser.AjaxRequest(this.API.ROBOT_LIST,
      // {

      // }, function(res) {
      //     that.isLoading = false
      // })
    },
    goDetail (item) {
      nextTick(() => {
        // router.push({
        //   name: 'robot',
        //   query: { market_id: item.market_id }
        // })
        uni.navigateTo({
          url:'../../robot/index'
        })

      })
    },
    getDeal (values) {
      if (values) {
        const valueJson = JSON.parse(values)
        return Number(valueJson.deal_amount).toFixed(6) || '-'
      }
      return '-'
    }
  }
}
</script>

<style scoped lang="less">
.title {
  background-color: #fff;
  padding: 10px 15px;
  font-size: 18px;
  font-weight: 600;
}
.asset-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .left {
    flex-shrink: 0;
  }
  .center {
    flex-grow: 1;
    min-width: 0;
  }
  .name {
    color: #333333;
    font-size: 16px;
    font-weight: 500;
  }
  .info {
    font-size: 12px;
    color: #888888;
  }
}
</style>
